﻿// <copyright file="FacetNameConverter.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-06</date>
// <summary>Facet name Converter</summary>

namespace NYTimes.ValueConverters
{
    using System;
    using System.Collections.Generic;
    using System.Windows.Data;
    using NYTimes.Data;

    /// <summary>
    /// Value converter for Facet dictionaries
    /// </summary>
    public class FacetNameConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Convert from a dictionary of facets to the facet collection
        /// </summary>
        /// <param name="value">The source data being passed to the target </param>
        /// <param name="targetType">The Type of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>The value to be passed to the target dependency property. </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }

            var facets = value as IDictionary<string, FacetCollection>;

            var key = parameter as string;

            if (facets.ContainsKey(key))
            {
                return facets[key].Facets;
            }

            return null;
        }

        /// <summary>
        /// Modifies the target data before passing it to the source object. This method is called only in TwoWay bindings. 
        /// </summary>
        /// <param name="value">The target data being passed to the source.</param>
        /// <param name="targetType">The Type of data expected by the source object.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic. </param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>The value to be passed to the source object.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
